package com.smommo.myapp.listener;

import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

public class MyApplicationListener implements ApplicationListener {
    //监听容器发布的事件，允许程序员执行自己的代码，完成事件驱动开发，
    // 它可以监听容器初始化完成、初始化失败等
    //事件.通常情况下可以使用监听器加载资源，开启定时任务等
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if(event instanceof ApplicationReadyEvent)
        {
            System.out.println("MyApp初始化完成");
        }
        if(event instanceof ApplicationFailedEvent)
        {
            System.out.println("MyApp初始化失败");
        }

    }

    @Override
    public boolean supportsAsyncExecution() {
        return ApplicationListener.super.supportsAsyncExecution();
    }
}
